cmake_minimum_required(VERSION 3.1)
cmake_policy(SET CMP0048 NEW)
project(switch_esim VERSION 0.1.0.0)

# options
option(DEBUG "enable debug" ON)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -O0 -Wno-unused-function -D_GNU_SOURCE -lmosquitto")

# include aux cmake scripts
include("cmake/Gengetopt.cmake")
ADD_GENGETOPT_FILES(CMDLINE cmdline.ggo)

# include aux cmake scripts
include("cmake/FindMosquitto.cmake")
set (EXTRALIB ${MOSQUITTO_LIBRARIES})

include_directories("${CMAKE_CURRENT_BINARY_DIR}"
	"${MOSQUITTO_INCLUDE_DIR}"
	"${PROJECT_BINARY_DIR}"
	"${PROJECT_SOURCE_DIR}"
	"${PROJECT_SOURCE_DIR}/include"
	)

set(SOLAR_ENERGY
lib/common.c
lib/buffer.c
lib/arg.c
lib/mqtt_client.c
main.c
)

set (STAGING_DIR $(STAGING_DIR))
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
	"${PROJECT_SOURCE_DIR}/config.h.in"
	"${PROJECT_BINARY_DIR}/config.h"
	)

# target
add_executable(switch_esim ${CMDLINE} ${SOLAR_ENERGY})
target_link_libraries(switch_esim ${EXTRALIB})

# install
install(TARGETS switch_esim DESTINATION bin)
